class WebpackLogPlugin {
  constructor(doneCallback, emitCallback) {
    this.done = doneCallback;
    this.emit = emitCallback;
  }

  apply(compiler) {
    compiler.hooks.emit.tap('LogWebpackPlugin', (compilation) => {
      let content = ' 生成的文件列表\r\n';
      content = Object.keys(compilation.assets).reduce((current, prev) => current + '- ' + prev + '\r\n', content);
      console.log(content);
      this.emit();
    });
    compiler.hooks.emit.tapAsync('abcd', (compilation, callback) => {
      this.emit();
      callback();
    });
    compiler.hooks.done.tap('LogWebpackPlugin', (args) => {
      console.log(' done ', args.hasErrors())
      this.done();
    });
    compiler.hooks.compilation.tap('helloworld', () => {
      console.log('starting a new compilation');
    })
  }
}

module.exports = WebpackLogPlugin;